//
//  ZCSearchCell.m
//  zctx
//
//  Created by 郭亚京 on 15/10/17.
//  Copyright © 2015年 sanliang. All rights reserved.
//

#import "ZCSearchCell.h"

@implementation ZCSearchCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier cellType:(ZCSearchCellType)type{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor whiteColor];
        if (type == ZCSearchCellTypeTitle) {
            [self.contentView addSubview:self.iconImgView];
            [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.contentView.centerY);
                make.left.equalTo(self.contentView.left).with.offset(18);
                make.height.mas_equalTo(@(50));
                make.width.mas_equalTo(@(50));
            }];
            self.iconImgView.layer.cornerRadius = 25;
            self.iconImgView.layer.masksToBounds = YES;
            
            [self.contentView addSubview:self.constView];
            [self.constView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.contentView.top).with.offset(0);
                make.bottom.equalTo(self.contentView.bottom).with.offset(0);
                make.left.equalTo(self.iconImgView.right).with.offset(10);
                make.right.equalTo(self.contentView.right).with.offset(0);
            }];
            
            [self.contentView addSubview:self.titleLable];
            [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.iconImgView.top).with.offset(0);
                make.left.equalTo(self.iconImgView.right).with.offset(10);
                make.right.equalTo(self.contentView.right).with.offset(-20);
                make.height.mas_equalTo(@(21));
                
            }];
            
            [self addFaqiBtn];
            [self addErrorBtn];
            [self addRightImgView];
        }else{
            self.backgroundColor = [UIColor colorWithHexString:@"#e7faf9"];
            [self.contentView addSubview:self.iconImgView];
            [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.contentView.centerY);
                make.right.equalTo(self.contentView.right).with.offset(-18);
                make.height.mas_equalTo(@(60));
                make.width.mas_equalTo(@(60));
            }];
            
            [self.contentView addSubview:self.bgImgView];
            [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.contentView.centerY);
                make.right.equalTo(self.iconImgView.left).with.offset(-10);
                make.left.equalTo(self.contentView.left).with.offset(18);
                make.height.mas_equalTo(@(68));
            }];
            
            [self.contentView addSubview:self.cirImgView];
            [self.cirImgView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.contentView.centerY);
                make.left.equalTo(self.contentView.left).with.offset(20);
                make.height.mas_equalTo(@(25));
                make.width.mas_equalTo(@(25));
            }];

            
            [self.contentView addSubview:self.titleLable];
            [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.contentView.centerY);
                make.left.equalTo(self.cirImgView.right).with.offset(0);
                make.right.equalTo(self.iconImgView.left).with.offset(-10);
                make.height.mas_equalTo(@(68));
            }];
            self.titleLable.text = @"哎呀，没有找到相关的产品消息呢~\r 发起检测让大家一起来参与食品安全吧!";
        }
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
}

-(void)setImgurl:(NSString *)imgurl{
    NSURL *url = [NSURL URLWithString:imgurl];
    [self.iconImgView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placehold_involved"]];
    
}

-(void)addFaqiBtn{
    [self.contentView addSubview:self.faqiBtn];
    [self.faqiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.iconImgView.bottom).with.offset(0);
        make.left.equalTo(self.iconImgView.right).with.offset(10);
        make.width.mas_equalTo(@(72));
        make.height.mas_equalTo(@(24));
        
    }];
}

-(void)addErrorBtn{
    [self.contentView addSubview:self.errorBtn];
    [self.errorBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.iconImgView.bottom).with.offset(0);
        make.left.equalTo(self.faqiBtn.right).with.offset(10);
        make.width.mas_equalTo(@(72));
        make.height.mas_equalTo(@(24));
    }];
}

-(void)addRightImgView{
    [self.constView addSubview:self.rightImgView];
    [self.rightImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.constView.centerY).with.offset(0);
        make.right.equalTo(self.constView.right).with.offset(-18);
        make.width.mas_equalTo(@(13));
        make.height.mas_equalTo(@(13));
    }];
}

-(UILabel *)titleLable{
    if (!_titleLable) {
        _titleLable = [[UILabel alloc]init];
        _titleLable.font = [UIFont systemFontOfSize:15];
        _titleLable.numberOfLines = 0;
        _titleLable.lineBreakMode = NSLineBreakByCharWrapping;
        _titleLable.textAlignment = NSTextAlignmentLeft;
        _titleLable.textColor = [UIColor colorWithHexString:@"#404040"];
    }
    return _titleLable;
}

-(UILabel *)infoLable{
    if (!_infoLable) {
        _infoLable = [[UILabel alloc]init];
        _infoLable.font = [UIFont systemFontOfSize:14];
        _infoLable.numberOfLines = 0;
        _infoLable.textAlignment = NSTextAlignmentRight;
    }
    return _infoLable;
}

-(UIImageView *)iconImgView{
    if (!_iconImgView) {
        _iconImgView = [[UIImageView alloc] init];
    }
    return _iconImgView;
}

-(UIImageView *)cirImgView{
    if (!_cirImgView) {
        _cirImgView = [[UIImageView alloc]init];
        _cirImgView.image = [UIImage imageNamed:@"scan_bg_cell_icon"];
    }
    return _cirImgView;
}

-(UIImageView *)bgImgView {
    if (!_bgImgView) {
        _bgImgView = [[UIImageView alloc]init];
        _bgImgView.image = [UIImage imageNamed:@"scan_bg_cell"];
    }
    return _bgImgView;
}

-(UIButton *)faqiBtn{
    if (!_faqiBtn) {
        _faqiBtn = [[UIButton alloc]init];
        [_faqiBtn setTitle:@"发起检测" forState:UIControlStateNormal];
        [_faqiBtn setTitleColor:[UIColor colorWithHexString:@"#1989C9"] forState:UIControlStateNormal];
        _faqiBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        _faqiBtn.layer.cornerRadius = 5;
        _faqiBtn.layer.borderWidth = 1;
        _faqiBtn.layer.borderColor = [UIColor colorWithHexString:@"#1989c9"].CGColor;
    }
    return _faqiBtn;
}

-(UIButton *)errorBtn{
    if (!_errorBtn) {
        _errorBtn = [[UIButton alloc]init];
        [_errorBtn setTitle:@"我要纠错" forState:UIControlStateNormal];
        [_errorBtn setTitleColor:[UIColor colorWithHexString:@"#ff8071"] forState:UIControlStateNormal];
        _errorBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        _errorBtn.layer.cornerRadius = 5;
        _errorBtn.layer.borderWidth = 1;
        _errorBtn.layer.borderColor = [UIColor colorWithHexString:@"#ff8071"].CGColor;
    }
    return _errorBtn;
}


-(UIView *)constView{
    if (!_constView) {
        _constView = [[UIView alloc]initWithFrame:CGRectZero];
        _constView.userInteractionEnabled = YES;
    }
    return _constView;
}

-(UIImageView *)rightImgView{
    if (!_rightImgView) {
        _rightImgView = [[UIImageView alloc]initWithFrame:CGRectZero];
        _rightImgView.image = [UIImage imageNamed:@"harm_right"];
    }
    return _rightImgView;
}

@end
